﻿/*
date	   :2010-6-22
author	   :by wangchao cwangchao@gmail.com
description:simulate thread loop,use like CreateThread(function(){var a;var b},1000);
*/
function CreateThread(threadproc,interval){
    var t = new Thread();
    t.ThreadProc = threadproc;
    t.Interval   = interval;
    t.Start();
    return t;
}
function Thread() {
    this.IsRun=true;
    this.ThreadProc = 0;
    this.Interval = 0;
    this.TimerId = 0;
}
Thread.prototype.Loop = function(t) {
    if (t.IsRun == true) {
        //loop
        t.TimerId = setTimeout(function() { t.Loop(t); }, t.Interval);
    t.ThreadProc();
    }
    else {
        clearTimeout(t.TimerId);
    }
}
Thread.prototype.Start = function() {
    this.Loop(this);
}
Thread.prototype.Stop  = function() {
this.IsRun = false;
clearInterval(this.TimerId);
}